import * as types from '../actionTypes/channel'
import axios from 'axios'
// thunk action  
export const getChannels = () => {
  return async dispatch => {
    // 做异步操作
    const res = await axios.get('http://geek.itheima.net/v1_0/channels')
    // res.data.data.channels 才是频道数据
    // 获取数据后调用dispatch跟新redux的状态
    dispatch({ type: types.GET_CHANGELS, payload: res.data.data.channels })
  }
}

// action creator
export const changeActive = channelId => {
  return {
    type: types.CHANGE_ACTIVE,
    payload: channelId
  }
}